export function filterHTMLTag (str) {
  let msg = str.replace(/<\/?[^>]*>/g, ''); //去除HTML Tag
  msg = msg.replace(/[|]*\n/, '') //去除行尾空格
  msg = msg.replace(/&npsp;/ig, ''); //去掉npsp
  return msg;
}

function getWindowWH () {
  return {
    width: document.documentElement.clientWidth || document.body.clientWidth,
    height: document.documentElement.clientHeight || document.body.clientHeight
  }
}
function getTargetWH (e) {
  return {
    width: e.offsetWidth,
    height: e.offsetHeight
  }
}

export function imgCenter (e, num) {
  const width = getTargetWH(e).width
  const height = getTargetWH(e).height
  if (width === height) {
    e.style.height = 100 + '%'
    e.style.left = 0
  }
  if (width < num || height < num) {
    if (width > height) {
      let cha = (width - height) / 2
      e.style.height = 100 + '%'
      e.style.left = -cha + 'px'
      e.style.top = 0
    } else {
      let cha = (height - width) / 2
      e.style.width = 100 + '%'
      e.style.top = -cha + 'px'
      e.style.left = 0
    }
  } else {
    if (width > height) {
      let rate = num / height
      let chaResult = (width - height) * rate / 2
      e.style.height = 100 + '%'
      e.style.left = -chaResult + 'px'
      e.style.top = 0
    } else {
      let rate = num / width
      let chaResult = (height - width) * rate / 2
      e.style.width = 100 + '%'
      e.style.top = -chaResult + 'px'
      e.style.left = 0
    }
  }
}